<template>
    <div>
        <div>
        <a-row>
            <a-col :span="8" v-for="item in house" :key="item.houseId">
                <a-card :title="'房间ID:' + item.houseId" style="width: 300px; height: 250px; margin-top: 10px;">
                    <el-button slot="extra" @click="toHousePage(item.houseId)">详情</el-button>
                    <el-button slot="extra" type="danger" @click="deleteHousePage(item.houseId)">删除</el-button>
                    <p>房间价格: {{item.housePrice }}元/月</p>
                    <p>房间面积: {{item.houseArea}}平方米</p>
                    <p>房间类型: {{item.roomNum }}室{{item.hallNum }}厅</p>
                    <p>租赁类型: <el-tag type="success">{{item.rentType === 1 ? "整租" : "合租"}}</el-tag></p>
                </a-card>
            </a-col>
        </a-row>
        </div>
        <div style="text-align: center; margin-top: 20px;">
            <el-pagination
                    background
                    :current-page.sync="current"
                    :page-size="pageSize"
                    :total="total"
                    layout="prev, pager, next"
                    @current-change="handleChange"
            >
            </el-pagination>
        </div>
    </div>
</template>

<script>
    export default {
        inject:['reload'],
        name: "HouseHome",
        data() {
            return {
                house: [],
                total: '',
                releaseId: '',
                pageSize: 0,
                current: 1
            }
        },
        created() {
            const _this = this
            _this.releaseId = localStorage.getItem("userId")
            _this.$http.get('house/selectHouseByReleaseId/' + _this.releaseId + '/' + _this.current).then(function (resp) {
                if (resp.data.code === 201)
                {
                    _this.house = resp.data.data.list
                    _this.total = resp.data.data.total
                    _this.pageSize = resp.data.data.pageSize
                }
            })
            _this.$router.push({name: 'HostHome'})
        },
        methods: {
            handleChange: function (e) {
                const _this = this
                console.log(e)
                _this.$http.get('house/selectHouseByReleaseId/' + _this.releaseId + '/' + e).then(function (resp) {
                    if (resp.data.code === 201)
                    {
                        _this.house = resp.data.data.list
                        _this.total = resp.data.data.total
                        _this.pageSize = resp.data.data.pageSize
                    }
                })
            },
            toHousePage: function (e) {
                this.$router.push({name: 'UpdateHousePage', params: {houseId: e}})
            },
            deleteHousePage: function (e) {
                let param = new URLSearchParams();
                param.append("houseId", e)
                const _this = this
                _this.$http.post('house/deleteOneHouse', param).then(function (resp) {
                    console.log(resp)
                })
                this.reload();
            }
        }
    }
</script>

<style scoped>

</style>
